import React from "react";
import { View, StyleSheet, TouchableOpacity, BackHandler } from "react-native";
import Article from "../../components/preAdmin/Article";
import { AntDesign } from "@expo/vector-icons";
import { useFocusEffect } from "@react-navigation/native";

const ArticlePreview = ({ route, navigation }) => {
  const { article } = route.params;

  // React.useLayoutEffect(() => {
  //   if (type == "editCard") {
  //     navigation.setOptions({
  //       headerRight: () => (
  //         <TouchableOpacity
  //           onPress={() => {
  //             navigation.push("EditArticle", {
  //               article: article,
  //               title: "编辑商品",
  //             });
  //           }}
  //         >
  //           <AntDesign name="edit" size={22} color="#fff" />
  //         </TouchableOpacity>
  //       ),
  //       headerLeft: () => (
  //         <TouchableOpacity
  //           onPress={() => {
  //             navigation.navigate("ArticleManage", { type: "normal" });
  //           }}
  //         >
  //           <AntDesign name="arrowleft" size={24} color="#fff" />
  //         </TouchableOpacity>
  //       ),
  //     });
  //   }
  // }, [navigation]);

  //自定义安卓返回键行为
  // useFocusEffect(
  //   React.useCallback(() => {
  //     // console.log("进来了xixixi");
  //     const onBackPress = () => {
  //       if (type == "editCard") {
  //         navigation.navigate("ArticleManage", { type: "normal" });
  //         return true;
  //       } else {
  //         return false;
  //       }
  //     };
  //     BackHandler.addEventListener("hardwareBackPress", onBackPress);
  //     return () =>
  //       BackHandler.removeEventListener("hardwareBackPress", onBackPress);
  //   }, [])
  // );

  return (
    <View style={styles.container}>
      <View style={{ marginBottom: 10 }}>
        <Article article={article} />
      </View>
    </View>
  );
};

var styles = StyleSheet.create({
  container: {
    height: "100%",
    backgroundColor: "white",
  },
});

export default ArticlePreview;
